
package edu.mobbuzz.page.menu;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.page.menu.contact.ContactPage;
import edu.mobbuzz.util.string.MenuString;
import edu.mobbuzz.util.theme.Theme;
import java.io.IOException;

public class ContactMenu extends Menu{
    private Form contactForm;
    private Container contactPanel; 
    
    private Label menuTitle;
    private Label menuIconLabel;
    private Label menuDescription;
    private Image menuIcon;   
        
    public ContactMenu(){
        contactForm = new Form(){
            public void keyPressed(int keyCode) {
                gameActionPerformed(keyCode);
            }        
        };             
        contactPanel = new Container();
        
        menuTitle = new Label(getMenuTitle());
        menuDescription = new Label();
        try {
            menuIcon = Image.createImage("/icons/contact.gif"); //Theme.getResources().getImage("contact.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        menuIconLabel = new Label(menuIcon);  
    }
    public void showPage(){ 
        menuIconLabel.setAlignment(Component.CENTER);
        menuIconLabel.getStyle().setMargin(50, 0, 0, 0);
        menuIconLabel.getStyle().setBgTransparency(0);  
        
        menuTitle.setAlignment(Component.LEFT);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setFgColor(0xF59FBC);
        menuTitle.getStyle().setBgTransparency(0);
         
        menuDescription.setText("Add your contact's friends");      
        menuDescription.setAlignment(Component.LEFT);
        menuDescription.getStyle().setFont(Theme.getFontDescriptionStyle("SansSerif"));
        menuDescription.getStyle().setFgColor(0xFFFFFF);
        menuDescription.getStyle().setMargin(0, 0, 5, 0);     
        menuDescription.getStyle().setBgTransparency(0);
                        
        contactPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        contactPanel.addComponent(menuIconLabel);
        contactPanel.addComponent(menuTitle);
        contactPanel.addComponent(menuDescription);
        
        contactForm.setLayout(new BorderLayout());
        contactForm.addComponent(BorderLayout.CENTER, contactPanel);        
        contactForm.addCommand(getExitCmd());
        contactForm.addCommand(getOnlineCmd());
        contactForm.addCommand(getSignOutCmd());
        contactForm.addCommand(new Command("Open") {
            public void actionPerformed(ActionEvent evt) {
               openContact();
            }
        });
                
        contactForm.setCommandListener(getActionlistener());
        contactForm.show();
    }
    public String getMenuTitle() {
        return MenuString.CONTACT;
    }
   
    public void gameActionPerformed(int keyCode){
        int game = Display.getInstance().getGameAction(keyCode);
        if(game == Display.GAME_FIRE){
            openContact();
        }else if(game == Display.GAME_RIGHT){
            getContactTransitionRight();
        }else if(game == Display.GAME_LEFT){
            getContactTransitionLeft();
        }
    }
    
     public void getContactTransitionRight(){
       contactForm.setTransitionOutAnimator(Theme.getTransitionOut());
       InboxMenu inboxMenu = new InboxMenu();
       inboxMenu.setExitCmd(getExitCmd());
       inboxMenu.setActionlistener(getActionlistener());
       inboxMenu.setMessaging(getMessaging());
       inboxMenu.showPage();
        
    }
    
    public void getContactTransitionLeft(){
       contactForm.setTransitionOutAnimator(Theme.getTransitionIn());
       RSSChannelMenu rssChannelMenu = new RSSChannelMenu();
       rssChannelMenu.setExitCmd(getExitCmd());
       rssChannelMenu.setActionlistener(getActionlistener());
       rssChannelMenu.setMessaging(getMessaging());
       rssChannelMenu.showPage();
    }
    
    public void openContact(){
       ContactPage contactPage = new ContactPage();
       contactPage.setExitCmd(getExitCmd());
       contactPage.setActionlistener(getActionlistener());
       contactPage.setMessaging(getMessaging());
       contactPage.showPage();
    }
}
